{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "def load_feat_float(path, dims):\n",
    "    return np.fromfile(path, dtype=np.float32).reshape(dims)\n",
    "\n",
    "def save_feat_float(path, feat):\n",
    "    feat.tofile(path)\n",
    "    \n",
    "def load_feat_int32(path, dims):\n",
    "    return np.fromfile(path, dtype=np.int32).reshape(dims)\n",
    "\n",
    "def save_feat_int32(path, feat):\n",
    "    feat.tofile(path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "volum = load_feat_float('./ground_truth/volume_data.bin', (6, 200, 200, 12, 64))\n",
    "volum_sum = volum.sum(0, keepdims=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([200, 200,  12], dtype=int32)"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# save_feat_float('./ground_truth/volume_sum_data.bin', volum_sum)\n",
    "load_feat_int32('./input/n_voxels_data.bin', (3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "metadata": {},
   "outputs": [],
   "source": [
    "save_feat_int32('./input/n_voxels_data_128_128_6.bin', np.array([128, 128, 6], dtype=np.int32))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "metadata": {},
   "outputs": [],
   "source": [
    "save_feat_int32('./input/n_voxels_data_128_128_12.bin', np.array([128, 128, 12], dtype=np.int32))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "metadata": {},
   "outputs": [],
   "source": [
    "save_feat_int32('./input/n_voxels_data_256_256_6.bin', np.array([256, 256, 6], dtype=np.int32))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "metadata": {},
   "outputs": [],
   "source": [
    "save_feat_int32('./input/n_voxels_data_256_256_12.bin', np.array([256, 256, 12], dtype=np.int32))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [],
   "source": [
    "save_feat_int32('./input/n_voxels_data_64_64_12.bin', np.array([64, 64, 12], dtype=np.int32))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "save_feat_int32('./input/n_voxels_data_256_256_1.bin', np.array([256, 256, 1], dtype=np.int32))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.5, 0.5, 0.5], dtype=float32)"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "load_feat_float('./input/voxel_size_data.bin', (3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0.,  0., -1.], dtype=float32)"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "load_feat_float('./input/origin_data.bin', (3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "save_feat_float('./input/voxel_size_data_05_05_3.bin', np.array([0.5, 0.5, 3], dtype=np.float32))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "save_feat_float('./input/voxel_size_data_05_05_6.bin', np.array([0.5, 0.5, 6], dtype=np.float32))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [],
   "source": [
    "save_feat_float('./input/voxel_size_data_05_05_1.bin', np.array([0.5, 0.5, 1.0], dtype=np.float32))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [],
   "source": [
    "save_feat_float('./input/voxel_size_data_05_05_025.bin', np.array([0.5, 0.5, 0.25], dtype=np.float32))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [],
   "source": [
    "save_feat_float('./input/voxel_size_data_05_05_019.bin', np.array([0.5, 0.5, 0.19], dtype=np.float32))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [],
   "source": [
    "save_feat_float('./input/voxel_size_data_05_05_005.bin', np.array([0.5, 0.5, 0.1], dtype=np.float32))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [],
   "source": [
    "save_feat_float('./input/voxel_size_data_1_1_05.bin', np.array([1.0, 1.0, 0.5], dtype=np.float32))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "metadata": {},
   "outputs": [],
   "source": [
    "save_feat_float('./input/voxel_size_data_078_078_1.bin', np.array([100/128, 100/128, 1.0], dtype=np.float32))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "metadata": {},
   "outputs": [],
   "source": [
    "save_feat_float('./input/voxel_size_data_078_078_05.bin', np.array([100/128, 100/128, 0.5], dtype=np.float32))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "metadata": {},
   "outputs": [],
   "source": [
    "save_feat_float('./input/voxel_size_data_039_039_1.bin', np.array([100/256, 100/256, 1.0], dtype=np.float32))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "metadata": {},
   "outputs": [],
   "source": [
    "save_feat_float('./input/voxel_size_data_039_039_05.bin', np.array([100/256, 100/256, 0.5], dtype=np.float32))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# feature"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "save_feat_float('./input/features_data_6_16_44_64.bin', np.random.randn(6, 16, 44, 64).astype(np.float32))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "metadata": {},
   "outputs": [],
   "source": [
    "save_feat_float('./input/features_data_6_32_88_64.bin', np.random.randn(6, 32, 88, 64).astype(np.float32))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "save_feat_float('./input/features_data_6_40_110_64.bin', np.random.randn(6, 40, 110, 64).astype(np.float32))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# project"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[ 7.6121468e+01, -3.6586349e+02, -1.5047620e+01, -6.2821236e+01],\n",
       "        [ 1.1526153e+02, -3.2093849e+01, -3.1706943e+02, -1.4543939e+02],\n",
       "        [ 9.3410861e-01, -3.5645434e-01, -1.9529385e-02, -4.7654495e-01]],\n",
       "\n",
       "       [[ 1.2946361e+01,  3.7904681e+02,  8.9906530e+00, -1.0909841e+02],\n",
       "        [-9.7573135e+01,  7.6232834e+01, -3.1665793e+02, -1.7584586e+02],\n",
       "        [-8.1953663e-01,  5.7290763e-01,  1.1688368e-02, -5.7950824e-01]],\n",
       "\n",
       "       [[ 3.4234146e+02, -1.5135385e+02, -7.3249741e+00, -1.0673708e+02],\n",
       "        [ 9.9888046e+01,  7.5892685e+01, -3.1457266e+02, -1.8689586e+02],\n",
       "        [ 8.3403468e-01,  5.5169547e-01,  4.2792447e-03, -6.4982831e-01]],\n",
       "\n",
       "       [[-2.0325552e+02, -2.0634384e+02, -3.4848785e+00, -2.0562627e+02],\n",
       "        [ 1.4010608e+00, -1.1895422e+02, -2.0318033e+02, -1.7548462e+02],\n",
       "        [-4.6402640e-03, -9.9996191e-01, -7.3895603e-03, -9.8954087e-01]],\n",
       "\n",
       "       [[ 3.1587366e+02,  2.0511452e+02,  5.7780108e+00, -1.0334457e+02],\n",
       "        [ 1.5828595e+00,  1.2866502e+02, -3.1429251e+02, -1.6873914e+02],\n",
       "        [-3.5391385e-03,  9.9982578e-01,  1.8327648e-02, -5.2849907e-01]],\n",
       "\n",
       "       [[-2.8738428e+02,  2.3523137e+02,  2.0167270e+00, -1.5738225e+02],\n",
       "        [-1.1057220e+02, -2.8654428e+01, -3.1755615e+02, -1.3060918e+02],\n",
       "        [-9.4819897e-01, -3.1632847e-01, -2.9239811e-02, -4.3990412e-01]]],\n",
       "      dtype=float32)"
      ]
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "load_feat_float('./input/projection_data.bin', (6, 3, 4))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "metadata": {},
   "outputs": [],
   "source": [
    "projection = load_feat_float('./input/projection_data.bin', (6, 3, 4))\n",
    "projection[:,:1,:] = projection[:,:1,:]*44/400\n",
    "projection[:,1:2,:] = projection[:,1:2,:]*16/255\n",
    "save_feat_float('./input/projection_data_d16_44.bin', projection)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {},
   "outputs": [],
   "source": [
    "projection = load_feat_float('./input/projection_data.bin', (6, 3, 4))\n",
    "projection[:,:1,:] = projection[:,:1,:]*88/400\n",
    "projection[:,1:2,:] = projection[:,1:2,:]*32/255\n",
    "save_feat_float('./input/projection_data_d32_88.bin', projection)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "projection = load_feat_float('./input/projection_data.bin', (6, 3, 4))\n",
    "projection[:,:1,:] = projection[:,:1,:]*110/400\n",
    "projection[:,1:2,:] = projection[:,1:2,:]*40/255\n",
    "save_feat_float('./input/projection_data_d40_110.bin', projection)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
